<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<body>
<script>

  let obj = {}

  //其实是一个闭包环境
  function defineReactive(data, key, val){
    if(arguments.length === 2){
      val = obj[key]
    }
    Object.defineProperty(data,key,{
      get(){
        console.log('正在读取' + key)
        return val
      },
      set(newValue){
        console.log('修改了a' + key)
        val = newValue
      }
    })
  }
  defineReactive(obj,'a',10)


</script>
</body>
</html>
